//
//  LHMainViewController.m
//  OCSinaWeibo
//
//  Created by LiHong on 15/10/27.
//  Copyright © 2015年 LiHong. All rights reserved.
//

#import "LHMainViewController.h"
#import "LHHomeTableViewController.h"
#import "LHMsgTableViewController.h"
#import "LHDiscoverTableViewController.h"
#import "LHProfileTableViewController.h"
#import "LHBaseTableViewController.h"
@interface LHMainViewController ()

@end

@implementation LHMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBar.tintColor = [UIColor orangeColor];
    // 首页
    LHHomeTableViewController *homeVc = [[LHHomeTableViewController alloc]init];
    [self addChildViewController:homeVc title:@"首页" imageName:@"tabbar_home"];
    
    // 消息
    LHMsgTableViewController *msgVc = [[LHMsgTableViewController alloc]init];
    [self addChildViewController:msgVc title:@"首页" imageName:@"tabbar_message_center"];
    
    // 撰写按钮
    UIViewController *view = [[UIViewController alloc]init];
    [self addChildViewController:view];
    
    // 发现
    LHDiscoverTableViewController *discoverVc = [[LHDiscoverTableViewController alloc]init];
    [self addChildViewController:discoverVc title:@"发现" imageName:@"tabbar_discover"];
    
    // 我
    LHProfileTableViewController *profileVc = [[LHProfileTableViewController alloc]init];
    [self addChildViewController:profileVc title:@"我" imageName:@"tabbar_profile"];
    
//    LHBaseTableViewController *baseVc = [[LHBaseTableViewController alloc]init];
//    baseVc.userLogin = NO;
    
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self addComposeButton];
}
/**
 *  添加子控制器
 *
 *  @param childController 子控制器
 *  @param title           子标题
 *  @param imageName       tabBar图片名
 */
- (void)addChildViewController:(UIViewController *)childController title:(NSString *)title imageName:(NSString *)imageName{
    childController.title = title;
    [childController.tabBarItem setImage:[UIImage imageNamed:imageName]];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:childController];
    [self addChildViewController:nav];
}

/**
 *  添加撰写按钮
 */
- (void)addComposeButton{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    // 按钮图片
    [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    // 按钮背景图片
    [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    CGFloat width = self.tabBar.bounds.size.width / 5;
    button.frame = CGRectMake(width * 2, 0, width, self.tabBar.bounds.size.height);
    [self.tabBar addSubview:button];
}

@end
